var code;

function encryptPwd(){
	var tag = validate();
	alert(tag);
	if(!tag){
		return;
	}
	alert(document.getElementsByName("userForm.password")[0].value);
	var mdPwd = hex_md5(document.getElementsByName("userForm.password")[0].value);
	alert("md: " + mdPwd);
	document.getElementsByName("userForm.password")[0].value = mdPwd;
	var form = document.getElementsByName("signUpForm")[0];
	form.submit();
}

function createCode()  {   
	code = "";  
	var codeLength = 6;//验证码的长度  
	var checkCode = document.getElementById("checkCode");  
	var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符，当然也可以用中文的  
     
	for(var i=0;i<codeLength;i++){  
		var charIndex = Math.floor(Math.random()*36);  
		code +=selectChar[charIndex];  
	}  
//  alert(code);  
	if(checkCode){  
		checkCode.className="code";  
		checkCode.value = code;  
	}  
}  

function validate ()  {  
	  alert("hello");
	  var inputCode = document.getElementsByName("userForm.words")[0].value;  
	  if(inputCode.length <=0)  {  
	      alert("input words！"); 
	      return false;
	  }else if(inputCode != code ){  
	     alert("验证码错误！"); 
	     createCode();//刷新验证码  
	     return false;
	  }else{  
	    alert("^-^ OK"); 
	    return true;
	  }  
    
  }  

function findUserByName(obj){
	var v = obj.value;
	var urlStr = APP_PATH + "/login!findUserByName.action";
	alert("根据名字查找用户!!" + v);
	var applyValue = "name=" + v;
	$.ajax({
		data:applyValue,
		url:urlStr,
		dataType:'text',
		type:'POST',
		success:function(ret){
			if(ret == "true"){
				alert("用户已经存在!!!");
			}else{
				alert(ret);
			}
		}
	});
	
}